package com.forum.framework.security.core;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 登录用户信息
 *
 * @author zihan.ouyang
 */
public class LoginUser implements UserDetails {
    private static final long serialVersionUID = 1L;
    public static final String INFO_KEY_NICKNAME = "nickname";
    private Long userId;
    /**
     * 验证码
     */
    private String code;
    /**
     * 唯一标识
     */
    private String uuid;

    private String token;
    /**
     * 用户类型
     */
    private Integer userType;
    /**
     * 额外的用户信息
     */
    private Map<String, String> info;
    /**
     * 权限列表
     */
    private List<String> roles;
    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private LocalDateTime expireTime;

    public LoginUser() {
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     *
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     *
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     *
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否可用 ,禁用的用户不能身份验证
     *
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return "";
    }

    @Override
    public String getUsername() {
        return "";
    }

    public Long getUserId() {
        return userId;
    }

    public LoginUser setUserId(Long userId) {
        this.userId = userId;
        return this;
    }

    public String getCode() {
        return code;
    }

    public LoginUser setCode(String code) {
        this.code = code;
        return this;
    }

    public String getUuid() {
        return uuid;
    }

    public LoginUser setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }

    public String getToken() {
        return token;
    }

    public LoginUser setToken(String token) {
        this.token = token;
        return this;
    }

    public List<String> getRoles() {
        return roles;
    }

    public LoginUser setRoles(List<String> roles) {
        this.roles = roles;
        return this;
    }

    public Long getLoginTime() {
        return loginTime;
    }

    public LoginUser setLoginTime(Long loginTime) {
        this.loginTime = loginTime;
        return this;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public LoginUser setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
        return this;
    }

    public Integer getUserType() {
        return userType;
    }

    public LoginUser setUserType(Integer userType) {
        this.userType = userType;
        return this;
    }

    public Map<String, String> getInfo() {
        return info;
    }

    public LoginUser setInfo(Map<String, String> info) {
        this.info = info;
        return this;
    }
}
